<template>
  <!-- 租赁房产管理 -->
  <base-breadcrumb :title="$route.meta.title">
    <!-- 搜索 -->
    <searchData
      :search-data="searchArr"
      @search="search"
      @onSelectChange="change"
    />
    <!-- 表格 -->
    <a-card :bordered="false">
      <!-- <title-name :title="$route.meta.title" /> -->
      <!-- <excel
        ref="exportAll"
        v-btn-permission="'oa_019_exp_02'"
        :file-name="excelName"
        is-click-generate="false"
      >
        <a-button
          slot="excelBtn"
          :loading="loading"
          :disabled="totalSize < 0"
          icon="export"
          type="primary"
          @click="exportAll"
        >
          导出
        </a-button>
      </excel> -->
      <!-- 表格 -->
      <list-table
        ref="table"
        row-key="id"
        :columns="columns"
        :request="loadData"
        :alert="true"
        show-size-changer
        show-quick-jumper
        :isHideFixed="true"
        :export-permission="{ select: 'oa_019_exp_02', all: 'oa_019_exp_02' }"
        :export-config="{ use: true, select: `${excelName}`, all: `${excelName}` }"
      >
        <template
          slot="action"
          slot-scope="text, record"
        >
          <a
            v-btn-permission="'oa_019_loo_01'"
            @click="handleManage(0, record)"
          >查看</a>
          <a-divider type="vertical" />
          <a @click="handleManage(1, record)">编辑</a>
          <!-- 删除 -->
          <a-divider type="vertical" />
          <a
            class="del_btn"
            @click="handleRemove(record.id)"
          >删除</a>
        </template>
      </list-table>
    </a-card>
  </base-breadcrumb>
</template>

<script>
// import { STable } from '@/components' // 表格
import { getParameterList } from '@/api/office/propertyManagement' // api
import TreeSelectOrganization from '@/components/TreeSelectOrganization'
import Selector from '@/components/Select/Selector'
import BasePage from '@/views/basePage' // 基础配置
import SelectCompanyAndProject from '@/components/Select/SelectCompanyAndProject'
import OrgTreeSelect from '@/components/OrgTreeSelect/index'
const searchArr = [
  // 搜索框
  {
    name: '单位',
    valueKey: 'searchQuery',
    type: OrgTreeSelect,
  },
  {
    name: '房屋性质',
    value: 'dataType',
    type: 'select',
    data: [
      {
        value: 'A',
        label: '租赁房',
      },
      {
        value: 'B',
        label: '自有房',
      },
      {
        value: 'C',
        label: '宿舍',
      },
    ],
  },
  {
    name: '房屋用途',
    valueKey: 'houseUseId',
    type: Selector,
    selectType: '3',
    urlType: 'office',
  },
]
const columns = [
  {
    title: '序号',
    width: 80,
    dataIndex: 'index',
    customRender() {
      return arguments[2] + 1
    },
  },
  {
    title: '所属单位',

    dataIndex: 'deptStr',
  },
  {
    title: '房屋性质',
    ellipsis: true,
    dataIndex: 'dataTypeStr',
  },
  {
    title: '房屋用途',
    ellipsis: true,
    dataIndex: 'houseUseStr',
  },
  {
    title: '小区名称',
    ellipsis: true,
    dataIndex: 'placeName',
    customRender(text, record, index) {
      return record.placeName || '-'
    },
  },

  {
    title: '房屋地址',
    ellipsis: true,
    dataIndex: 'placeAddress',
    customRender(text, record, index) {
      return record.placeAddress || '-'
    },
  },
  {
    title: '门牌号',
    ellipsis: true,
    dataIndex: 'houseNum',
    customRender(text, record, index) {
      return record.houseNum || '-'
    },
  },
  {
    title: '建筑面积(m²)',

    dataIndex: 'builtArea',
    customRender(text, record, index) {
      return record.builtArea || '-'
    },
  },
  {
    title: '房产原值(元)',

    dataIndex: 'houseAmount',
    customRender(text, record, index) {
      return record.houseAmount || '-'
    },
  },
  {
    title: '租金（元/月）',
    dataIndex: 'rentFeeAmount',

    customRender(text, record, index) {
      return record.rentFeeAmount || '-'
    },
  },
  {
    title: '合同租赁单价(元/m²/月)',
    dataIndex: 'areaAmount',

    customRender(text, record, index) {
      return record.areaAmount || '-'
    },
  },
  {
    title: '租金（元/年）',
    dataIndex: 'rentYearAmount',

    customRender(text, record, index) {
      return record.rentYearAmount || '-'
    },
  },
  {
    title: '租赁期限',
    dataIndex: 'leaseDateStr',

    customRender(text, record, index) {
      return record.leaseDateStr || '-'
    },
  },
  {
    title: '剩余租赁期(月)',
    dataIndex: 'surplusMonth',

    customRender(text, record, index) {
      return record.surplusMonth || '-'
    },
  },
  {
    title: '物业费(元/月)',
    dataIndex: 'propertyFeeAmount',

    customRender(text, record, index) {
      return record.propertyFeeAmount || '-'
    },
  },
]
export default {
  name:'a'+Date.now(),
  extends: new BasePage(),
  components: {
    // STable,
  },
  data() {
    this.columns = columns
    this.searchArr = searchArr
    return {
      queryParam: {}, // 查询参数
      totalSize: 0,
      loading: false,
      excelName:'房产管理台账',
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, { query: this.queryParam })
        return getParameterList(requestParameters).then((res) => {
          this.totalSize = res.totalSize
          return res
        })
      }, // 加载数据方法 必须为 Promise 对象
      // removeApi: { remove: remove }, // api
      editModel: 0,
      form: {},
    }
  },
  mounted() {
    // this.$refs.exportAll.tableToExcelFile(this.$refs.table)
  },
  methods: {
    change(e){
      console.log(e)
      this.excelName = e.name+"房产管理台账"
    },
    /*
     * 导出所有的数据
     * */
    exportAll() {
      // 参数：查询条件、导出的回调
      if (this.totalSize) {
        this.list(false, this.$refs.exportAll.setDataAndGenerate)
      } else {
        this.$message.warning('没有可导出的数据')
      }
    },
    list(params, callback) {
      this.loading = true
      let _this = this
      let searchData = Object.assign(
        {
          pageSize: this.totalSize,
          pageNo: 1,
        },
        params,
        this.queryParam
      )

      getParameterList(searchData).then((res) => {
        if (res.code === 200) {
          if (callback) {
            if (res.data.length) {
              callback(res.data)
            } else {
              this.$message.warning('没有可导出的数据')
            }
            this.loading = false
            return
          }
          _this.tableData = res.data
          _this.totalSize = res.totalSize
        }
        this.loading = false
      })
    },
    // 搜索
    search(value) {
      value && (this.queryParam = value)
      this.$refs.table.refresh(true)
    },
  },
}
</script>
